<template>
	<view class="content">
		<topMenu></topMenu>
	
		<view class="page-manipulation">
			<view class="page-manipulation-item" v-for="(item,index) in deviceListData">
				<label for="">{{item.mName || '--'}}</label>
				<switch :checked="item.isEnable == 1?true:false" @change="deviceChangeFn($event,item)" style="transform:scale(0.7)"/>
			</view>
		
		</view>
		<tab-bar ref="tabBar"></tab-bar>
	</view>
</template>

<script>
import {switchMode,deviceList,setTime,setTemp,switchChange} from "@/api/api.js";
import topMenu from '../../components/top-menu/top-menu.vue'
	    export default {
	        components:{
	            topMenu
	        },
	        data() {
	            return {
					deviceListData:[]
	            }
	        },
	 
			 
	        onLoad() {
	            
	        },
			onTabItemTap(e) {
			            // tab 点击时执行，此处直接接收单击事件
			            console.log(e)
			        },
			mounted() { 
			 this.getDeviceList()
			},
	        methods: {
				checkModel() {
					uni.showModal({
					    title: "提示",
					    content: "确认要切换到时控模式吗？",
					    success: function (res) {
					       if (res.confirm) {
					       let obj ={
							  model:1
					         }
					       switchMode(obj).then(res => {
							if(res.code==0){
								uni.showToast({ title: res.msg, duration: 2000})
							}else{
								uni.showToast({ title: res.msg, duration: 2000})
							}
					       									
					       })
					       } else {
					   //  uni.reLaunch({url:'../skms/index'});
					       }
					   },
					});
					
				},
				//获取用户信息
				getDeviceList() {
					let param = {
						phone: "18793002958"
					} 
					uni.showLoading({  title: '请稍后' });
					deviceList(param).then(res => {
						if (res.code == 0 && res.data) { //有用户信息
							 console.log(res)
							 if(res.data.length>0){
								this.deviceListData = res.data
								 uni.hideLoading();
							 }
						} else { //无用户信息
							 
						}
					}).catch(res => { 
					 
					})
				},
				deviceChangeFn(e,item){
					let value = e.detail.value
					let obj = {
						isEnable:e.detail.value?'1':'0',
						id:item.id
					}
					uni.showLoading({  title: '请稍后' });
					switchChange(obj).then(res => {
						if(res.code==0){
							uni.showToast({ title: res.msg, duration: 2000})
						}else{
							uni.showToast({ title: res.msg, duration: 2000})
						}
					 
						 
					})
				},
	            confrim(e){
	                    console.log(e.time)//确定事件 =>12:30-17:30
	                },
	                cancel(e){
	                    console.log(e.time)//取消事件 =>12:30-17:30
	                }
	        }
	    }
</script>

<style scoped lang="scss" scoped>
	.content{
		.page-manipulation{
			width: 90%;
			border-top: 3px solid rgba(151, 151, 151, 1); 
			padding: 60rpx 0;
			margin: 0 auto;
			.page-manipulation-item{
				border-radius: 8px;
				background: rgba(238, 245, 255, 1);
				padding: 40rpx 32rpx;
				margin-bottom: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}
	}
	
</style>
